﻿using PwjCy.Lite.Common;
using PwjCy.Lite.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace PwjCy.Lite.EntityLite.Imp
{
    public class PwjCyOjbectTypeDescription : IPwjCyOjbectTypeDescription
    {
        private Type _DescriptType { get; set; }
        public PwjCyOjbectTypeDescription(Type descriptType)
        {
            _DescriptType = descriptType;
        }

        /// <summary>
        /// 获取数据库字段属性数组 
        /// </summary>
        /// <returns></returns>
        public PropertyInfo[] PwjCyFields
        {
            get
            {
                string pwjcyFieldKey = this.GetType().FullName + "_" + _DescriptType.FullName + "_PwjCyFields_IPwjCyObject";
                if (null != PLServices.HashCacheHelper.GetCache<PropertyInfo[]>(pwjcyFieldKey))
                {
                    return PLServices.HashCacheHelper.GetCache<PropertyInfo[]>(pwjcyFieldKey);
                }
                IList<PropertyInfo> propertyInfoList = new List<PropertyInfo>();
                foreach (var pro in TypeHelper.Instance.GetPropertyInfo(_DescriptType))
                {
                    var att = pro.GetCustomAttributes(false).Select(attribute => attribute as IgnoreDataTypeAttribute).FirstOrDefault();
                    if (null == att)
                    {
                        propertyInfoList.Add(pro);
                    }
                }
                PLServices.HashCacheHelper.AddCache<PropertyInfo[]>(propertyInfoList.ToArray(), pwjcyFieldKey);
                return propertyInfoList.ToArray();
            }
        }
    }
}
